/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FileInformation.helpers;


import java.io.File;
import java.io.IOException;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 *
 * @author Nobody
 */
public class ExcelInformationRetriever extends AbstractFileHelper {

    private String[] sheetNames;
    private String choosedSheetName = "";
    private ExtensionRetriever extensionRetriever;
    public ExcelInformationRetriever(File file) {
        super(file);
        extensionRetriever = new ExtensionRetriever(file);
    }

  
    @Override
    public void execute() throws IOException {
        extensionRetriever.execute();
        if (extensionRetriever.isExcel2003File()) {
            try {
                Workbook workbook = Workbook.getWorkbook(file);
                sheetNames = workbook.getSheetNames();
            } catch (BiffException ex) {
               throw new IOException(ex);
            }
        } else if (extensionRetriever.isExcel7File()) {
            XSSFWorkbook workBook = new XSSFWorkbook(file.getAbsolutePath());
            String[] arrayOfSheetNames = new String[workBook.getNumberOfSheets()];
            for (int i = 0; i < workBook.getNumberOfSheets(); ++i) {
                arrayOfSheetNames[i] = workBook.getSheetName(i);
            }
            sheetNames = arrayOfSheetNames;
        } else {
            sheetNames = new String[0];
        }
    }

    

    public String getChoosedSheetName() {
        return choosedSheetName;
    }

    public String[] getSheetNames() {
        return sheetNames;
    }

    public void setChoosedSheetName(String choosedSheetName) {
        this.choosedSheetName = choosedSheetName;
    }
}
